package com.web.farme.pojo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Classname Result
 * @Description TODO
 * @Date 2021/4/11 上午10:29
 * @Created by sakura
 */
@Data
@NoArgsConstructor
public class Results<T> implements Serializable {

    private String message;
    private boolean success;
    private Integer code;
    private T data;

    public Results(String message, boolean success, Integer code, T data) {
        this.message = message;
        this.success = success;
        this.code = code;
        this.data = data;
    }

    public static <T> Results<T> buildSuccess(String message, boolean success, Integer code, T data) {
        return new Results<T>(message, success, code, data);
    }

    public static <T> Results<T> buildSuccess(String messgae, T data) {
        Results<T> results = new Results<>();
        results.data = data;
        results.message = messgae;
        results.code = 0;
        results.success = true;
        return results;
    }

    public static <T> Results<T> buildFail(String message, T data) {
        Results<T> results = new Results<>();
        results.message = message;
        results.data = data;
        results.code = 1;
        results.success = false;
        return results;
    }

    public static <T> Results<T> buildFail(String message) {
        Results<T> results = new Results<>();
        results.message = message;
        results.code = 1;
        results.success = false;
        return results;
    }

    @Override
    public String toString() {
        return "Results{" +
                "message='" + message + '\'' +
                ", success=" + success +
                ", code=" + code +
                ", data=" + data +
                '}';
    }
}
